package spil;

import desktop_resources.GUI;

public abstract class Ownable extends Field {
	protected int price;
	protected Player owner;

	public abstract int getRent();

	public Ownable(int price, int fieldNumber){
		super(fieldNumber);
		this.price = price;
	}
	
	public Player getOwner() {
		return owner;
	}
	
	public void buy(Player buyer) {
		if(buyer.getBalance() > price) {
			owner = buyer;
			buyer.getAccount().withdraw(price);
			GUI.getUserButtonPressed(buyer + " k�bte " + title, "ok");
			GUI.setOwner(fieldNumber, buyer.getName());
		}
		else GUI.getUserButtonPressed(buyer + " har ikke r�d til gaden", "ok");
	}
	
	public void lose(Player p) {
		if(owner == p) {
			owner = null;
			GUI.removeOwner(fieldNumber);
		}
	}
}
